﻿@using KRM.Core
@using KRM.Core.Library
@model KRM.Core.vOrderView_OrderSummary
@{
    var vOrderItemStatus = ViewBag.vOrderItemStatus;
    var customerid = ViewBag.CustomerID;// db.tblOrders.Find(Model.OrderID).CustomerID;
    var notshowTotalValue = (Model.OrderMethod == "Trade" && !Users.Current(User.Identity.Name).HasPermission(Permissions.CanSeeTradePriceInOrder));
    var storeId = ViewBag.StoreID;
    var urlPayment = storeId != 74 ? "/orderview/paymenthistory?orderref=" + Model.OrderRef : "/orderview/refundtesco?orderid=" + Model.OrderID;
}
@if (ViewBag.IsOver14DayReturnPolicy)
{
    <h5 style="color: red; margin: 0px; line-height: 24px;">Return policy over 14 days</h5>
}
<strong>Order status:</strong>

@if (vOrderItemStatus != null)
{
    var color = vOrderItemStatus.StatusID > 0 ? "Green" : "red";
    if (vOrderItemStatus.StatusID == -2) // held
    {
        int seperatorIdx = string.IsNullOrEmpty(vOrderItemStatus.Status) ? 0 : vOrderItemStatus.Status.IndexOf('-');
        if (seperatorIdx > 0)
        {
    <h3 style="color: @color; text-align: center">@vOrderItemStatus.Status.Substring(0, seperatorIdx)</h3>
    <p class="text-center" style="color: @color">
        @*@if (ViewBag.FailDelivery)
        {
            @Html.Raw("Failed Delivery")
        }
        else if (ViewBag.IsCollected)
        {
            @Html.Raw("Item Collected")
        }
        else
        {*@
            @Html.Raw(vOrderItemStatus.Status.Remove(0, seperatorIdx + 1))
        @*}*@
    </p>
        }
        else
        {
    <h3 style="color: @color; text-align: center">@vOrderItemStatus.Status</h3>
        }
    }
    else
    {
    <h3 style="color: @color; text-align: center">@vOrderItemStatus.Status</h3>
    }
}
<strong>Customer order:</strong>
<form action="/orderview/orderdetail">
    <div class="row-fluid">
        <div class="span9">
            @Html.DropDownList("OrderRef", null, new { @class = "input-block-level" })
        </div>
        <div class="span3">
            <button type="submit" class="btn btn-primary" style="width: 100%">Go</button>
        </div>
    </div>
</form>

<table class="tbl-ordersummary">
    <tr>
        <td style="width: 75px">Order date</td>
        <td>: </td>
        <td>@(string.IsNullOrEmpty(Model.DatePlaced.ToString()) ? "" : Model.DatePlaced.ToString("dd/MM/yyyy HH:mm:ss"))</td>
    </tr>
    <tr>
        <td>Method</td>
        <td>:</td>
        <td>@(Model.IsEspresso == true ? "Espresso" : Model.OrderMethod)</td>
    </tr>
    <tr>
        <td>Store</td>
        <td>: </td>
        <td>@Model.StoreName</td>
    </tr>
    <tr>
        <td>Agent</td>
        <td>: </td>
        <td>@Model.UserPlaced</td>
    </tr>
    <tr>
        <td>Invoice no</td>
        <td>: </td>
        <td>@Model.InvoiceNumber</td>
    </tr>
    @if (!notshowTotalValue)
    {<tr>
        <td>Net value</td>
        <td>: </td>
        <td>@(Model.NetOrderValue > 0 ? string.Format("{0:C}", Model.NetOrderValue) : Model.NetOrderValue.ToString())</td>
    </tr>
    }
    <tr>
        <td>Discount</td>
        <td>: </td>
        <td>@(Model.DiscountValue > 0 ? string.Format("{0:C}", Model.DiscountValue) : Model.DiscountValue.ToString()) </td>
    </tr>
    @if (!notshowTotalValue)
    {<tr>
        <td>Total value</td>
        <td>: </td>
        <td>@(Model.OrderValue > 0 ? string.Format("{0:C}", Model.OrderValue) : Model.OrderValue.ToString())</td>
    </tr>}
</table>
<br />
<div class="row-fluid">
    <div class="span6">
        <a href="javascript:;" onclick="PopupCenter('@urlPayment', 980, 600)" class="btn btn-ordersummary">Payment history</a>
    </div>
    <div class="span6">
        <a href="javascript:;" onclick="PopupCenter('/orderview/ddinvoice?orderref=@Model.OrderRef',900,500)" class="btn btn-ordersummary">DD Invoice</a>
    </div>
</div>
<div class="row-fluid">
    <div class="span6">
        <a href="javascript:;" onclick="printinvoice(@Model.OrderID);" class="btn btn-ordersummary">Print invoice</a>
    </div>
    <div class="span6">
        <a href="javascipt:;" @*onclick="PopupCenter('/orderview/contactsupplier?orderid=@Model.OrderID',800,600)"*@ class="btn btn-ordersummary">Contact supplier</a>
    </div>
</div>
<div class="row-fluid">
    <div class="span6">
        <a href="javascript:;" onclick="PopupCenter('/orderview/issuevoucher?customerid=@customerid',500,500)" class="btn btn-ordersummary">Issue voucher</a>
    </div>
    <div class="span6">
        <a href="/orderview/PrintCancellation?orderid=@Model.OrderID" class="btn btn-ordersummary">Print cancellation</a>
    </div>
</div>
